package com.wz.project.api.tmsMatnr.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.api.tmsMatnr.domain.TmMatnr;
import com.wz.project.api.tmsMatnr.service.ITmMatnrService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * tms物品信息Controller
 * 
 * @author wz
 * @date 2022-11-28
 */
@Controller
@RequestMapping("/tmsMatnr/tmsMatnr")
public class TmMatnrController extends BaseController
{
    private String prefix = "tmsMatnr";

    @Autowired
    private ITmMatnrService tmMatnrService;

//    @RequiresPermissions("tmsMatnr:tmsMatnr:view")
    @GetMapping()
    public String tmsMatnr()
    {
        return prefix + "/tmsMatnr";
    }

    /**
     * 查询tms物品信息列表
     */
//    @RequiresPermissions("tmsMatnr:tmsMatnr:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TmMatnr tmMatnr)
    {
        startPage();

        List<TmMatnr> list = tmMatnrService.selectTmMatnrList(tmMatnr);
        return getDataTable(list);
    }
    @RequestMapping("/list1")
    @ResponseBody
    public TableDataInfo list1(TmMatnr tmMatnr)
    {
        startPage();
        tmMatnr.setFid(tmMatnr.getInStockId());
        tmMatnr.setInStockId(tmMatnr.getInStockId().split("-")[0]);

        List<TmMatnr> list = tmMatnrService.selectTmMatnrList(tmMatnr);
        return getDataTable(list);
    }

    /**
     * 导出tms物品信息列表
     */
//    @RequiresPermissions("tmsMatnr:tmsMatnr:export")
    @Log(title = "tms物品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TmMatnr tmMatnr)
    {
        List<TmMatnr> list = tmMatnrService.selectTmMatnrList(tmMatnr);
        ExcelUtil<TmMatnr> util = new ExcelUtil<TmMatnr>(TmMatnr.class);
        return util.exportExcel(list, "tmsMatnr");
    }

    /**
     * 新增tms物品信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存tms物品信息
     */
    @RequiresPermissions("tmsMatnr:tmsMatnr:add")
    @Log(title = "tms物品信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TmMatnr tmMatnr)
    {
        return toAjax(tmMatnrService.insertTmMatnr(tmMatnr));
    }

    /**
     * 修改tms物品信息
     */
    @GetMapping("/edit/{matnr}")
    public String edit(@PathVariable("matnr") String matnr, ModelMap mmap)
    {
        TmMatnr tmMatnr = tmMatnrService.selectTmMatnrById(matnr);
        mmap.put("tmMatnr", tmMatnr);
        return prefix + "/edit";
    }

    /**
     * 修改保存tms物品信息
     */
    @RequiresPermissions("tmsMatnr:tmsMatnr:edit")
    @Log(title = "tms物品信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TmMatnr tmMatnr)
    {
        return toAjax(tmMatnrService.updateTmMatnr(tmMatnr));
    }

    /**
     * 删除tms物品信息
     */
//    @RequiresPermissions("tmsMatnr:tmsMatnr:remove")
    @Log(title = "tms物品信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tmMatnrService.deleteTmMatnrByIds(ids));
    }
}
